package com.legendshop.openportal.sdk.service;

import cn.hutool.core.lang.TypeReference;
import com.legendshop.openportal.sdk.client.ClientExecutionParams;
import com.legendshop.openportal.sdk.client.http.HttpResponseAnalyzerSupport;
import com.legendshop.openportal.sdk.client.http.handler.DefaultHttpResponseHandler;
import com.legendshop.openportal.sdk.model.OpenPageSupport;
import com.legendshop.openportal.sdk.model.OpenResult;
import com.legendshop.openportal.sdk.model.request.*;
import com.legendshop.openportal.sdk.model.request.v4.*;
import com.legendshop.openportal.sdk.model.response.CategoryTreeVO;
import com.legendshop.openportal.sdk.model.response.ProdPageResponse;
import com.legendshop.openportal.sdk.model.response.ProductV2VO;
import com.legendshop.openportal.sdk.model.response.prod.*;
import com.legendshop.openportal.sdk.model.response.v4.*;

import java.util.List;

/**
 * @Description: 开放平台商品服务
 * @Author lwj
 * @data 2024/6/28
 **/
public class ProductService extends BaseService {

    /**
     * 查询商品池信息
     *
     * @param request
     * @return
     */
    public static OpenResult<ProdPageResponse> queryProdPage(ProdPageRequest request) {
        return execute(request, ProdPageResponse.class);
    }

    /**
     * 查询商品类目树
     *
     * @param request
     * @return
     */
    public static OpenResult<List<CategoryTreeVO>> queryCategoryPage(ProdCatrgoryRequest request) {
        return execute(request, new TypeReference<List<CategoryTreeVO>>() {
        });
    }

    /**
     * 查询供应商商品类目树
     *
     * @param request
     * @return
     */
    public static OpenResult<List<CategoryTreeVO>> querySupplierCategoryPage(SupplierProdCatrgoryRequest request) {
        return execute(request, new TypeReference<List<CategoryTreeVO>>() {
        });
    }


    /**
     * 查询商品列表
     *
     * @param request
     * @return
     */
    public static OpenResult<OpenPageSupport<ProductV2VO>> queryProdListPage(ProdListPageRequest request) {
        return execute(request, new TypeReference<OpenPageSupport<ProductV2VO>>() {
        });
    }


    /**
     * 获取商品详情
     *
     * @param request
     * @return
     */
    public static OpenResult<ProductDetailResponse> getDetail(ProdDetailRequest request) {
        return execute(request, ProductDetailResponse.class);
    }


    /**
     * 查询商品价格
     *
     * @param request
     * @return
     */
    public static OpenResult<List<ProdPriceResponse>> queryProdPrice(ProdPriceRequest request) {
        return execute(request, new TypeReference<List<ProdPriceResponse>>() {
        });
    }


    /**
     * 查询商品库存
     *
     * @param request
     * @return
     */
    public static OpenResult<List<ProdStockResponse>> queryProdStock(ProdStockRequest request) {
        return execute(request, new TypeReference<List<ProdStockResponse>>() {
        });
    }


    /**
     * 查询商品上下架状态
     *
     * @param request
     * @return
     */
    public static OpenResult<List<ProdStatusResponse>> queryProdStatus(ProdStatusRequest request) {
        return execute(request, new TypeReference<List<ProdStatusResponse>>() {
        });
    }


    /**
     * 查询商品起售数量
     *
     * @param request
     * @return
     */
    public static OpenResult<List<ProdStartSaleAmountResponse>> queryProdStartSaleAmount(ProdStartSaleAmountRequest request) {
        return execute(request, new TypeReference<List<ProdStartSaleAmountResponse>>() {
        });
    }

    /**
     * 校验商品可售性
     *
     * @param request
     * @return
     */
    public static OpenResult<List<CheckSkuSaleStateAndStockResponse>> checkSkuSaleStateAndStock(CheckSkuSaleStateAndStockRequest request) {
        return execute(request, new TypeReference<List<CheckSkuSaleStateAndStockResponse>>() {
        });
    }

    //**************************************************V4部分**************************************************

    /**
     * 获取商品详情
     *
     * @param request
     * @return
     */
    public static OpenResult<ProductDetailV4Response> getDetailV4(ProdDetailV4Request request) {
        return execute(request, ProductDetailV4Response.class);
    }


    /**
     * 查询商品列表
     *
     * @param prodListPageV4Request
     * @return
     */
    public static OpenResult<OpenPageSupport<ProductV4Response>> getProdPageV4(ProdListPageV4Request prodListPageV4Request) {
        return execute(prodListPageV4Request, new TypeReference<OpenPageSupport<ProductV4Response>>() {
        });
    }

    /**
     * 查询优惠券列表
     *
     * @param couponPageV4Request
     * @return
     */
    public static OpenResult<OpenPageSupport<CouponV4Response>> getCouponPageV4(CouponPageV4Request couponPageV4Request) {
        return execute(couponPageV4Request, new TypeReference<OpenPageSupport<CouponV4Response>>() {});
    }

    /**
     * 批量发放优惠券
     *
     * @param request
     * @return
     */
    public static OpenResult<CouponBatchImportV4Response> importCouponPageV4(CouponBatchImportV4Request request) {
        ClientExecutionParams<CouponBatchImportV4Request, CouponBatchImportV4Response> clientExecutionParams
                = new ClientExecutionParams<>(true, request, true
                    , new DefaultHttpResponseHandler<>(CouponBatchImportV4Response.class, HttpResponseAnalyzerSupport.getAnalyzerChain()));
        return execute(clientExecutionParams);
    }


    /**
     * 保存商品
     *
     * @param request
     * @return
     */
    public static OpenResult<ProdSaveV4Response> saveProd(ProdSaveV4Request request) {
        ClientExecutionParams<ProdSaveV4Request, ProdSaveV4Response> clientExecutionParams
                = new ClientExecutionParams<>(true, request, true
                       , new DefaultHttpResponseHandler<>(ProdSaveV4Response.class, HttpResponseAnalyzerSupport.getAnalyzerChain()));
        return execute(clientExecutionParams);
    }


    /**
     * 查询商品类目树
     *
     * @param request
     * @return
     */
    public static OpenResult<List<ProdCategoryV4Response>> queryCategoryV4(ProdCategoryV4Request request) {
        return execute(request, new TypeReference<List<ProdCategoryV4Response>>() {
        });
    }

    /**
     * 查询商品运费规则
     * @param request
     * @return
     */
    public static OpenResult<List<ProdTransportV4Response>> queryTransportV4(ProdTransportV4Request request) {
        return execute(request, new TypeReference<List<ProdTransportV4Response>>() {});
    }

}
